package com.itrus.ica.ra;

import com.itrus.cert.Names;
import com.itrus.cert.X509Certificate;
import com.itrus.ica.IcaClientBase;
import com.itrus.ica.IcaConnection;
import com.itrus.ica.IcaUnavailable;
import com.itrus.ica.PipeInteger;
import com.itrus.raapi.info.CertInfo;
import com.itrus.raapi.info.UserInfo;
import com.itrus.raapi.result.QueryResult;
import com.itrus.raapi.result.SqlResult;
import com.itrus.util.CertUtils;
import com.itrus.util.CipherUtils;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
import org.apache.commons.logging.Log;

public class RaAdminManager extends IcaClientBase
{
  private void addUserInfoToProperties(UserInfo paramUserInfo, Properties paramProperties)
  {
    ifNotNullThenAdd(paramProperties, "USER_ID", paramUserInfo.getUserIdString());
    ifNotNullThenAdd(paramProperties, "ACCOUNT_ID", paramUserInfo.getAccountIdString());
    ifNotNullThenAdd(paramProperties, "USER_ID_RANDOM", paramUserInfo.getUserIdRandom());
    ifNotNullThenAdd(paramProperties, "USER_NAME", paramUserInfo.getUserName());
    ifNotNullThenAdd(paramProperties, "USER_SURNAME", paramUserInfo.getUserSurName());
    ifNotNullThenAdd(paramProperties, "CERT_SERIALNUMBER", CertUtils.getICAValidSerialNumber(paramUserInfo.getUserSerialNumber()));
    ifNotNullThenAdd(paramProperties, "USER_EMAIL", paramUserInfo.getUserEmail());
    ifNotNullThenAdd(paramProperties, "USER_ORGANIZATION", paramUserInfo.getUserOrganization());
    ifNotNullThenAdd(paramProperties, "USER_ORGUNIT", paramUserInfo.getUserOrgUnit());
    ifNotNullThenAdd(paramProperties, "USER_COUNTRY", paramUserInfo.getUserCountry());
    ifNotNullThenAdd(paramProperties, "USER_STATE", paramUserInfo.getUserState());
    ifNotNullThenAdd(paramProperties, "USER_LOCALITY", paramUserInfo.getUserLocality());
    ifNotNullThenAdd(paramProperties, "USER_STREET", paramUserInfo.getUserStreet());
    ifNotNullThenAdd(paramProperties, "USER_DNS", paramUserInfo.getUserDns());
    ifNotNullThenAdd(paramProperties, "USER_IP", paramUserInfo.getUserIp());
    ifNotNullThenAdd(paramProperties, "USER_TITLE", paramUserInfo.getUserTitle());
    ifNotNullThenAdd(paramProperties, "USER_DESCRIPTION", paramUserInfo.getUserDescription());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD1", paramUserInfo.getUserAdditionalField1());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD2", paramUserInfo.getUserAdditionalField2());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD3", paramUserInfo.getUserAdditionalField3());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD4", paramUserInfo.getUserAdditionalField4());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD5", paramUserInfo.getUserAdditionalField5());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD6", paramUserInfo.getUserAdditionalField6());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD7", paramUserInfo.getUserAdditionalField7());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD8", paramUserInfo.getUserAdditionalField8());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD9", paramUserInfo.getUserAdditionalField9());
    ifNotNullThenAdd(paramProperties, "USER_ADDTIONAL_FIELD10", paramUserInfo.getUserAdditionalField10());
    ifNotNullThenAdd(paramProperties, "CERT_STATUS", paramUserInfo.getCertStatus());
    ifNotNullThenAdd(paramProperties, "CERT_NOTBEFORE", paramUserInfo.getCertNotBefore());
    ifNotNullThenAdd(paramProperties, "CERT_NOTAFTER", paramUserInfo.getCertNotAfter());
    ifNotNullThenAdd(paramProperties, "CERT_KMC_REQ2", paramUserInfo.getCertKmcReq2());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_OVERRIDE_VALIDITY", paramUserInfo.getCertReqOverrideValidity());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_BUF", paramUserInfo.getCertReqBuffer());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_CHALLENGE", paramUserInfo.getCertReqChallenge());
    ifNotNullThenAdd(paramProperties, "CERT_REQ_COMMENT", paramUserInfo.getCertReqComment());
  }

  private CertInfo getCertInfo(Properties paramProperties)
  {
    CertInfo localCertInfo = new CertInfo();
    localCertInfo.setPasscode(paramProperties.getProperty("PASSCODE"));
    localCertInfo.setPassCodeId(paramProperties.getProperty("PASSCODE_ID"));
    localCertInfo.setStatus(paramProperties.getProperty("PASSCODE_STATUS"));
    localCertInfo.setUserStrId(paramProperties.getProperty("USER_ID"));
    localCertInfo.setAccountStrId(paramProperties.getProperty("ACCOUNT_ID"));
    localCertInfo.setUserIdRandom(paramProperties.getProperty("USER_ID_RANDOM"));
    localCertInfo.setUserName(paramProperties.getProperty("USER_NAME"));
    localCertInfo.setUserName(paramProperties.getProperty("NAME"));
    localCertInfo.setUserSurName(paramProperties.getProperty("USER_SURNAME"));
    localCertInfo.setUserSerialNumber(paramProperties.getProperty("USER_SERIALNUMBER"));
    localCertInfo.setUserEmail(paramProperties.getProperty("USER_EMAIL"));
    localCertInfo.setUserEmail(paramProperties.getProperty("EMAIL"));
    localCertInfo.setUserOrganization(paramProperties.getProperty("USER_ORGANIZATION"));
    localCertInfo.setUserOrgUnit(paramProperties.getProperty("USER_ORGUNIT"));
    localCertInfo.setUserCountry(paramProperties.getProperty("USER_COUNTRY"));
    localCertInfo.setUserState(paramProperties.getProperty("USER_STATE"));
    localCertInfo.setUserLocality(paramProperties.getProperty("USER_LOCALITY"));
    localCertInfo.setUserStreet(paramProperties.getProperty("USER_STREET"));
    localCertInfo.setUserDns(paramProperties.getProperty("USER_DNS"));
    localCertInfo.setUserIp(paramProperties.getProperty("USER_IP"));
    localCertInfo.setUserTitle(paramProperties.getProperty("USER_TITLE"));
    localCertInfo.setUserDescription(paramProperties.getProperty("USER_DESCRIPTION"));
    localCertInfo.setUserAdditionalField1(paramProperties.getProperty("USER_ADDTIONAL_FIELD1"));
    localCertInfo.setUserAdditionalField2(paramProperties.getProperty("USER_ADDTIONAL_FIELD2"));
    localCertInfo.setUserAdditionalField3(paramProperties.getProperty("USER_ADDTIONAL_FIELD3"));
    localCertInfo.setUserAdditionalField4(paramProperties.getProperty("USER_ADDTIONAL_FIELD4"));
    localCertInfo.setUserAdditionalField5(paramProperties.getProperty("USER_ADDTIONAL_FIELD5"));
    localCertInfo.setUserAdditionalField6(paramProperties.getProperty("USER_ADDTIONAL_FIELD6"));
    localCertInfo.setUserAdditionalField7(paramProperties.getProperty("USER_ADDTIONAL_FIELD7"));
    localCertInfo.setUserAdditionalField8(paramProperties.getProperty("USER_ADDTIONAL_FIELD8"));
    localCertInfo.setUserAdditionalField9(paramProperties.getProperty("USER_ADDTIONAL_FIELD9"));
    localCertInfo.setUserAdditionalField10(paramProperties.getProperty("USER_ADDTIONAL_FIELD10"));
    localCertInfo.setCertStrId(paramProperties.getProperty("CERT_ID"));
    localCertInfo.setCertIdRandom(paramProperties.getProperty("CERT_ID_RANDOM"));
    localCertInfo.setCertStatus(paramProperties.getProperty("CERT_STATUS"));
    localCertInfo.setCertStatus(paramProperties.getProperty("STATUS"));
    localCertInfo.setCertReqDate(paramProperties.getProperty("CERT_REQ_DATE"));
    localCertInfo.setCertReqTransid(paramProperties.getProperty("CERT_REQ_TRANSID"));
    localCertInfo.setCertReqNonce(paramProperties.getProperty("CERT_REQ_NONCE"));
    localCertInfo.setCertReqBufType(paramProperties.getProperty("CERT_REQ_BUF_TYPE"));
    localCertInfo.setCertReqChallenge(paramProperties.getProperty("CERT_REQ_CHALLENGE"));
    localCertInfo.setCertReqComment(paramProperties.getProperty("CERT_REQ_COMMENT"));
    localCertInfo.setCertApproveDate(paramProperties.getProperty("CERT_APPROVE_DATE"));
    localCertInfo.setCertRejectDate(paramProperties.getProperty("CERT_REJECT_DATE"));
    localCertInfo.setCertSignDate(paramProperties.getProperty("CERT_SIGN_DATE"));
    localCertInfo.setCertSignBufP7(paramProperties.getProperty("CERT_SIGN_BUF_P7"));
    localCertInfo.setCertSerialNumber(paramProperties.getProperty("CERT_SERIALNUMBER"));
    localCertInfo.setCertNotBefore(paramProperties.getProperty("CERT_NOTBEFORE"));
    localCertInfo.setCertNotAfter(paramProperties.getProperty("CERT_NOTAFTER"));
    Date localDate1 = localCertInfo.getCertNotBeforeDate();
    Date localDate2 = localCertInfo.getCertNotAfterDate();
    if ((localDate1 != null) && (localDate2 != null))
    {
      Date localDate3 = new Date();
      if (((localDate3.before(localDate1)) || (localDate3.after(localDate2))) && ("VALID".equals(localCertInfo.getCertStatus())))
        localCertInfo.setCertStatus("OVERDUE");
    }
    localCertInfo.setCertIssuerHashMd5(paramProperties.getProperty("CERT_ISSUER_HASH_MD5"));
    localCertInfo.setCertIssuerDN(paramProperties.getProperty("CERT_ISSUER_DN"));
    localCertInfo.setCertSubjectHashMd5(paramProperties.getProperty("CERT_SUBJECT_HASH_MD5"));
    localCertInfo.setCertSubjectDN(paramProperties.getProperty("CERT_SUBJECT_DN"));
    localCertInfo.setCertSuspendDate(paramProperties.getProperty("CERT_SUSPEND_DATE"));
    localCertInfo.setCertRevokeDate(paramProperties.getProperty("CERT_REVOKE_DATE"));
    localCertInfo.setCertRevokeReason(paramProperties.getProperty("CERT_REVOKE_REASON"));
    localCertInfo.setCertRenewalDate(paramProperties.getProperty("CERT_RENEWAL_DATE"));
    localCertInfo.setCertRenewalPrevStrId(paramProperties.getProperty("CERT_RENEWAL_PREV_ID"));
    localCertInfo.setCertRenewalNextId(paramProperties.getProperty("CERT_RENEWAL_NEXT_ID"));
    localCertInfo.setCertReqOverrideValidity(paramProperties.getProperty("CERT_REQ_OVERRIDE_VALIDITY"));
    localCertInfo.setCertReqBuffer(paramProperties.getProperty("CERT_REQ_BUF"));
    localCertInfo.setCertSignBuf(paramProperties.getProperty("CERT_SIGN_BUF"));
    localCertInfo.setCertPin(paramProperties.getProperty("CERT_PIN"));
    localCertInfo.setCertType(paramProperties.getProperty("CERT_TYPE"));
    localCertInfo.setCertDeliverMode(paramProperties.getProperty("CERT_DELIVER_MODE"));
    localCertInfo.setCertApproveAdmin1(paramProperties.getProperty("CERT_APPROVE_ADMIN1"));
    localCertInfo.setCertApproveAdmin2(paramProperties.getProperty("CERT_APPROVE_ADMIN2"));
    localCertInfo.setCertRenewEmailDeliver(paramProperties.getProperty("CERT_RENEWEMAIL_DELIVER"));
    localCertInfo.setCertReqPublicKey(paramProperties.getProperty("CERT_REQ_PUBLICKEY"));
    localCertInfo.setCertReqPublicKeyHashMd5(paramProperties.getProperty("CERT_REQ_PUBLICKEY_HASH_MD5"));
    return localCertInfo;
  }

  private void ifNotExistThenAdd(Properties paramProperties, String paramString1, String paramString2)
  {
    if (paramProperties.getProperty(paramString1) == null)
      paramProperties.setProperty(paramString1, paramString2);
  }

  private void ifNotNullThenAdd(Properties paramProperties, String paramString1, String paramString2)
  {
    if ((paramString2 != null) && (!"".equals(paramString2)))
      paramProperties.setProperty(paramString1, paramString2);
  }

  private void setPickupResultCharacter(Properties paramProperties, AdminEnrollResult paramAdminEnrollResult)
  {
    paramAdminEnrollResult.setCertApproveDate(paramProperties.getProperty("CERT_APPROVE_DATE"));
    paramAdminEnrollResult.setCertIssuerDN(paramProperties.getProperty("CERT_ISSUER_DN"));
    paramAdminEnrollResult.setCertIssuerHashMD5(paramProperties.getProperty("CERT_ISSUER_HASH_MD5"));
    paramAdminEnrollResult.setCertSubjectDN(paramProperties.getProperty("CERT_SUBJECT_DN"));
    paramAdminEnrollResult.setCertSubjectHashMD5(paramProperties.getProperty("CERT_SUBJECT_HASH_MD5"));
    paramAdminEnrollResult.setCertNotBefore(paramProperties.getProperty("CERT_NOTBEFORE"));
    paramAdminEnrollResult.setCertNotAfter(paramProperties.getProperty("CERT_NOTAFTER"));
    paramAdminEnrollResult.setCertReqDate(paramProperties.getProperty("CERT_REQ_DATE"));
    paramAdminEnrollResult.setCertSerialNumber(paramProperties.getProperty("CERT_SERIALNUMBER"));
    paramAdminEnrollResult.setCertSignBuf(paramProperties.getProperty("CERT_SIGN_BUF"));
    paramAdminEnrollResult.setCertSignBufP7(paramProperties.getProperty("CERT_SIGN_BUF_P7"));
    paramAdminEnrollResult.setCertSignDate(paramProperties.getProperty("CERT_SIGN_DATE"));
    paramAdminEnrollResult.setCertKmcReq2(paramProperties.getProperty("CERT_KMC_REQ2"));
    paramAdminEnrollResult.setCertKmcRep1(paramProperties.getProperty("CERT_KMC_REP1"));
    paramAdminEnrollResult.setCertKmcRep2(paramProperties.getProperty("CERT_KMC_REP2"));
    paramAdminEnrollResult.setCertKmcRep3(paramProperties.getProperty("CERT_KMC_REP3"));
  }

  private void setSqlResultCharacter(Properties paramProperties, SqlResult paramSqlResult)
  {
    paramSqlResult.setSqlRecordsCount(paramProperties.getProperty("SQL_RECORDS_COUNT"));
    paramSqlResult.setSqlRecordsIndex(paramProperties.getProperty("SQL_RECORDS_INDEX"));
    paramSqlResult.setSqlScriptRuntime(paramProperties.getProperty("SQL_SCRIPT_RUNTIME"));
  }

  public void addRaService(String paramString)
  {
    addIcaService(paramString);
  }

  public AdminOperationResult raAdminApprove(X509Certificate paramX509Certificate, int paramInt1, int paramInt2)
    throws IcaUnavailable
  {
    if (paramInt1 <= 0)
    {
      AdminOperationResult localAdminOperationResult = new AdminOperationResult();
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("参数不正确:CERT_ID");
      return localAdminOperationResult;
    }
    Properties localProperties = new Properties();
    localProperties.setProperty("CERT_ID", String.valueOf(paramInt1));
    if (paramInt2 > 0)
      localProperties.setProperty("CERT_REQ_OVERRIDE_VALIDITY", String.valueOf(paramInt2));
    return raAdminOperation(paramX509Certificate, "AdminApprove", localProperties);
  }

  public AdminEnrollResult raAdminEnrollDoubleUser(X509Certificate paramX509Certificate, UserInfo paramUserInfo)
    throws IcaUnavailable
  {
    AdminEnrollResult localAdminEnrollResult = new AdminEnrollResult();
    if (paramUserInfo == null)
    {
      localAdminEnrollResult.setReturnCode("A002");
      localAdminEnrollResult.setExtMessage("缺少必要参数:UserInfo");
      return localAdminEnrollResult;
    }
    if (paramUserInfo.getCertKmcReq2() == null)
      paramUserInfo.setCertKmcReq2("kmcReqVersion=20101209");
    return raAdminEnrollUser(paramX509Certificate, paramUserInfo);
  }

  public AdminEnrollResult raAdminEnrollUser(X509Certificate paramX509Certificate, UserInfo paramUserInfo)
    throws IcaUnavailable
  {
    AdminEnrollResult localAdminEnrollResult = new AdminEnrollResult();
    if ((paramUserInfo.getUserName() == null) || ("".equals(paramUserInfo.getUserName())))
    {
      localAdminEnrollResult.setReturnCode("A002");
      localAdminEnrollResult.setExtMessage("缺少必要参数:USER_NAME（CommonName）");
      return localAdminEnrollResult;
    }
    if ((paramUserInfo.getUserEmail() == null) || ("".equals(paramUserInfo.getUserEmail())))
    {
      localAdminEnrollResult.setReturnCode("A002");
      localAdminEnrollResult.setExtMessage("缺少必要参数:USER_EMAIL");
      return localAdminEnrollResult;
    }
    if ((paramUserInfo.getCertReqChallenge() == null) || ("".equals(paramUserInfo.getCertReqChallenge())))
    {
      localAdminEnrollResult.setReturnCode("A002");
      localAdminEnrollResult.setExtMessage("缺少必要参数:CERT_REQ_CHALLENGE");
      return localAdminEnrollResult;
    }
    if (paramUserInfo.getCertReqBuffer() == null)
    {
      localAdminEnrollResult.setReturnCode("A002");
      localAdminEnrollResult.setExtMessage("缺少必要参数:CERT_REQ_BUF");
      return localAdminEnrollResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "AdminEnrollUser");
    localProperties1.setProperty("ICA_ADMIN_SUBJECT", paramX509Certificate.getICASubjectDNString());
    localProperties1.setProperty("ICA_ADMIN_ISSUER", paramX509Certificate.getICAIssuerDNString());
    localProperties1.setProperty("ICA_ADMIN_CERT_SERIALNUMBER", paramX509Certificate.getICASerialNumber());
    localProperties1.setProperty("ICA_ADMIN_CERT_SERIALNUMBER_0", paramX509Certificate.getICASerialNumber().toLowerCase());
    Names localNames = paramX509Certificate.getSubjectNames();
    localProperties1.setProperty("ACCOUNT_HASH", CipherUtils.md5(localNames.getItem("O") + localNames.getItem("OU")).toUpperCase());
    addUserInfoToProperties(paramUserInfo, localProperties1);
    localProperties1.setProperty("CERT_REQ_BUF_TYPE", "PKCS10");
    localProperties1.setProperty("KEYMODE", "ENROLL");
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localAdminEnrollResult.setReturnCode(l);
      if (l == 0L)
        setPickupResultCharacter(localProperties2, localAdminEnrollResult);
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localAdminEnrollResult.getMessage());
      return localAdminEnrollResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localAdminEnrollResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public RaAdminLoginResult raAdminLogin(X509Certificate paramX509Certificate)
    throws IcaUnavailable
  {
    RaAdminLoginResult localRaAdminLoginResult = new RaAdminLoginResult();
    if (paramX509Certificate == null)
    {
      localRaAdminLoginResult.setReturnCode("A002");
      localRaAdminLoginResult.setExtMessage("缺少必要参数:ICA_ADMIN_CERT");
      return localRaAdminLoginResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "OnSiteAdminLogin");
    localProperties1.setProperty("ADMIN_TYPE", "RA");
    localProperties1.setProperty("ICA_ADMIN_SUBJECT", paramX509Certificate.getICASubjectDNString());
    localProperties1.setProperty("ICA_ADMIN_ISSUER", paramX509Certificate.getICAIssuerDNString());
    localProperties1.setProperty("ICA_ADMIN_CERT_SERIALNUMBER", paramX509Certificate.getICASerialNumber());
    localProperties1.setProperty("ICA_ADMIN_CERT_SERIALNUMBER_0", paramX509Certificate.getICASerialNumber().toLowerCase());
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localRaAdminLoginResult.setReturnCode(l);
      if (l == 0L)
      {
        localRaAdminLoginResult.setAdminId(localProperties2.getProperty("ADMIN_ID"));
        localRaAdminLoginResult.setAdminCertSerialNumber(localProperties2.getProperty("ADMIN_CERT_SERIALNUMBER"));
        localRaAdminLoginResult.setAdminStatus(localProperties2.getProperty("ADMIN_STATUS"));
        localRaAdminLoginResult.setAdminSecurity(localProperties2.getProperty("ADMIN_SECURITY"));
        localRaAdminLoginResult.setAdminCert(localProperties2.getProperty("ADMIN_CERT"));
        localRaAdminLoginResult.setAdminName(localProperties2.getProperty("ADMIN_NAME"));
        localRaAdminLoginResult.setAdminEmail(localProperties2.getProperty("ADMIN_EMAIL"));
        localRaAdminLoginResult.setAdminFieldName(localProperties2.getProperty("ADMIN_FIELD_NAME"));
        localRaAdminLoginResult.setAdminFieldValue(localProperties2.getProperty("ADMIN_FIELD_VALUE"));
        localRaAdminLoginResult.setAccountId(localProperties2.getProperty("ACCOUNT_ID"));
        localRaAdminLoginResult.setAccountHash(localProperties2.getProperty("ACCOUNT_HASH"));
        localRaAdminLoginResult.setParentHash(localProperties2.getProperty("PARENT_HASH"));
        localRaAdminLoginResult.setAccountOrganization(localProperties2.getProperty("ACCOUNT_ORGANIZATION"));
        localRaAdminLoginResult.setAccountOrgUnit(localProperties2.getProperty("ACCOUNT_ORGUNIT"));
        localRaAdminLoginResult.setAccountMinAdmin(localProperties2.getProperty("ACCOUNT_MIN_ADMIN"));
        localRaAdminLoginResult.setAccountCertDeliver(localProperties2.getProperty("ACCOUNT_CERT_DELIVER"));
        localRaAdminLoginResult.setAccountType(localProperties2.getProperty("ACCOUNT_TYPE"));
        localRaAdminLoginResult.setAccountServiceEndDate(localProperties2.getProperty("ACCOUNT_SERVICE_END_DATE"));
        localRaAdminLoginResult.setAccountServiceUrl(localProperties2.getProperty("ACCOUNT_SERVICE_URL"));
        localRaAdminLoginResult.setAccountStatus(localProperties2.getProperty("ACCOUNT_STATUS"));
        localRaAdminLoginResult.setFeaturePasscode(localProperties2.getProperty("FEATURE_PASSCODE"));
        localRaAdminLoginResult.setFeatureKMC(localProperties2.getProperty("FEATURE_KMC"));
        localRaAdminLoginResult.setFeatureAutoAdmin(localProperties2.getProperty("FEATURE_AUTO_ADMIN"));
        localRaAdminLoginResult.setSqlRecordsIndex(localProperties2.getProperty("SQL_RECORDS_INDEX"));
        localRaAdminLoginResult.setSqlRecordsCount(localProperties2.getProperty("SQL_RECORDS_COUNT"));
      }
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localRaAdminLoginResult.getMessage());
      return localRaAdminLoginResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localRaAdminLoginResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public AdminOperationResult raAdminOperation(X509Certificate paramX509Certificate, String paramString, Properties paramProperties)
    throws IcaUnavailable
  {
    AdminOperationResult localAdminOperationResult = new AdminOperationResult();
    if (paramX509Certificate == null)
    {
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("缺少必要参数:ICA_ADMIN_CERT");
      return localAdminOperationResult;
    }
    if (paramString == null)
    {
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("缺少必要参数:OPERATION");
      return localAdminOperationResult;
    }
    if (paramProperties == null)
    {
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("缺少参数集合");
      return localAdminOperationResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", paramString);
    localProperties1.setProperty("ICA_ADMIN_SUBJECT", paramX509Certificate.getICASubjectDNString());
    localProperties1.setProperty("ICA_ADMIN_ISSUER", paramX509Certificate.getICAIssuerDNString());
    localProperties1.setProperty("ICA_ADMIN_CERT_SERIALNUMBER", paramX509Certificate.getICASerialNumber());
    localProperties1.setProperty("ICA_ADMIN_CERT_SERIALNUMBER_0", paramX509Certificate.getICASerialNumber().toLowerCase());
    Enumeration localEnumeration = paramProperties.propertyNames();
    int i = 0;
    while (true)
    {
      IcaConnection localIcaConnection;
      if (i >= paramProperties.size())
        localIcaConnection = null;
      try
      {
        localIcaConnection = getConnection();
        localAdminOperationResult.setReturnCode(localIcaConnection.request(localProperties1, localProperties2));
        if (localIcaConnection != null)
          localIcaConnection.close();
        this.log.debug(localAdminOperationResult.getMessage());
        return localAdminOperationResult;
        String str = (String)localEnumeration.nextElement();
        localProperties1.setProperty(str, paramProperties.getProperty(str));
        i++;
      }
      catch (IOException localIOException)
      {
        while (true)
        {
          localAdminOperationResult.setReturnCode(1L);
          if (localIcaConnection != null)
            localIcaConnection.close();
        }
      }
      finally
      {
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
  }

  public AdminOperationResult raAdminReject(X509Certificate paramX509Certificate, int paramInt)
    throws IcaUnavailable
  {
    if (paramInt <= 0)
    {
      AdminOperationResult localAdminOperationResult = new AdminOperationResult();
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("参数不正确:CERT_ID");
      return localAdminOperationResult;
    }
    Properties localProperties = new Properties();
    localProperties.setProperty("CERT_ID", String.valueOf(paramInt));
    return raAdminOperation(paramX509Certificate, "AdminReject", localProperties);
  }

  public AdminOperationResult raAdminResume(X509Certificate paramX509Certificate, String paramString)
    throws IcaUnavailable
  {
    if (paramString == null)
    {
      AdminOperationResult localAdminOperationResult = new AdminOperationResult();
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("缺少必要参数:CERT_SERIALNUMBER");
      return localAdminOperationResult;
    }
    Properties localProperties = new Properties();
    localProperties.setProperty("CERT_SERIALNUMBER", paramString);
    return raAdminOperation(paramX509Certificate, "AdminResume", localProperties);
  }

  public AdminOperationResult raAdminRevoke(X509Certificate paramX509Certificate, String paramString1, String paramString2)
    throws IcaUnavailable
  {
    if (paramString1 == null)
    {
      AdminOperationResult localAdminOperationResult1 = new AdminOperationResult();
      localAdminOperationResult1.setReturnCode("A002");
      localAdminOperationResult1.setExtMessage("缺少必要参数:CERT_SERIALNUMBER");
      return localAdminOperationResult1;
    }
    if (paramString2 == null)
    {
      AdminOperationResult localAdminOperationResult2 = new AdminOperationResult();
      localAdminOperationResult2.setReturnCode("A002");
      localAdminOperationResult2.setExtMessage("缺少必要参数:CERT_REVOKE_REASON");
      return localAdminOperationResult2;
    }
    Properties localProperties = new Properties();
    localProperties.setProperty("CERT_SERIALNUMBER", paramString1);
    localProperties.setProperty("CERT_REVOKE_REASON", paramString2);
    return raAdminOperation(paramX509Certificate, "AdminRevoke", localProperties);
  }

  public AdminOperationResult raAdminSuspend(X509Certificate paramX509Certificate, String paramString)
    throws IcaUnavailable
  {
    if (paramString == null)
    {
      AdminOperationResult localAdminOperationResult = new AdminOperationResult();
      localAdminOperationResult.setReturnCode("A002");
      localAdminOperationResult.setExtMessage("缺少必要参数:CERT_SERIALNUMBER");
      return localAdminOperationResult;
    }
    Properties localProperties = new Properties();
    localProperties.setProperty("CERT_SERIALNUMBER", CertUtils.getICAValidSerialNumber(paramString));
    return raAdminOperation(paramX509Certificate, "AdminSuspend", localProperties);
  }

  public QueryResult raQueryCert(int paramInt1, int paramInt2, int paramInt3, int paramInt4, String paramString)
    throws IcaUnavailable
  {
    QueryResult localQueryResult = new QueryResult();
    if (paramInt1 <= 0)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("参数不正确:ACCOUNT_ID");
      return localQueryResult;
    }
    if (paramInt2 <= 0)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("参数不正确:ADMIN_ID");
      return localQueryResult;
    }
    if (paramInt3 <= 0)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("参数不正确:USER_ID");
      return localQueryResult;
    }
    if (paramInt4 <= 0)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("参数不正确:CERT_ID");
      return localQueryResult;
    }
    if (paramString == null)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("缺少必要参数:SQL_TEMPLATE_FILENAME");
      return localQueryResult;
    }
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "Query");
    localProperties1.setProperty("ACCOUNT_ID", String.valueOf(paramInt1));
    localProperties1.setProperty("ADMIN_ID", String.valueOf(paramInt2));
    localProperties1.setProperty("USER_ID", String.valueOf(paramInt3));
    localProperties1.setProperty("CERT_ID", String.valueOf(paramInt4));
    localProperties1.setProperty("SQL_TEMPLATE_FILENAME", paramString);
    localProperties1.setProperty("SQL_RECORDS_INDEX", "0");
    localProperties1.setProperty("SQL_RECORDS_ALL", "YES");
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localQueryResult.setReturnCode(l);
      if (l == 0L)
      {
        setSqlResultCharacter(localProperties2, localQueryResult);
        String str = localProperties2.getProperty("SQL_RECORDS_COUNT");
        if ((str != null) && (Integer.valueOf(str).intValue() > 0))
        {
          localQueryResult.setResult(getCertInfo(localProperties2));
          localQueryResult.setTotal(1);
        }
      }
      if (localIcaConnection != null)
        localIcaConnection.close();
      this.log.debug(localQueryResult.getMessage());
      return localQueryResult;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localQueryResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public QueryResult raQueryCerts(int paramInt1, int paramInt2, UserInfo paramUserInfo, int paramInt3, int paramInt4, String paramString1, String paramString2, String paramString3)
    throws IcaUnavailable
  {
    QueryResult localQueryResult = new QueryResult();
    if (paramInt1 <= 0)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("参数不正确:ACCOUNT_ID");
      return localQueryResult;
    }
    if (paramInt2 <= 0)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("参数不正确:ADMIN_ID");
      return localQueryResult;
    }
    if (paramString1 == null)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("缺少必要参数:SQL_TEMPLATE_FILENAME");
      return localQueryResult;
    }
    if (paramString2 == null)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("缺少必要参数:NEXT_RESULT_TAG");
      return localQueryResult;
    }
    if (paramString3 == null)
    {
      localQueryResult.setReturnCode("A002");
      localQueryResult.setExtMessage("缺少必要参数:USER_TOTAL");
      return localQueryResult;
    }
    Properties localProperties1 = new Properties();
    Vector localVector1 = new Vector();
    localProperties1.setProperty("ACCOUNT_ID", String.valueOf(paramInt1));
    localProperties1.setProperty("ADMIN_ID", String.valueOf(paramInt2));
    localProperties1.setProperty("NEXT_RESULT_TAG", paramString2);
    localProperties1.setProperty("TOTAL_TAG", paramString3);
    if (paramInt3 <= 0)
      paramInt3 = 1;
    int i = paramInt4 * (paramInt3 - 1);
    localProperties1.put("SQL_CONTINUE", "YES");
    localProperties1.put("SQL_RECORDS_INDEX", String.valueOf(i));
    localProperties1.put("SQL_WANTTOGET_RECORDS", String.valueOf(paramInt4));
    ifNotNullThenAdd(localProperties1, "SQL_TEMPLATE_FILENAME", paramString1);
    addUserInfoToProperties(paramUserInfo, localProperties1);
    localProperties1.setProperty("OPERATION", "Query");
    IcaConnection localIcaConnection = null;
    try
    {
      localIcaConnection = getConnection();
      PipeInteger localPipeInteger = new PipeInteger();
      Properties localProperties2 = new Properties();
      long l = localIcaConnection.request(localProperties1, localVector1, localPipeInteger, localProperties2);
      localQueryResult.setReturnCode(l);
      Vector localVector2;
      if (l == 0L)
      {
        setSqlResultCharacter(localProperties2, localQueryResult);
        localVector2 = new Vector();
      }
      for (int j = 0; ; j++)
      {
        if (j >= localVector1.size())
        {
          localQueryResult.setPageSize(paramInt4);
          localQueryResult.setTotal(localPipeInteger.getValue());
          this.log.debug("满足条件的记录一共有[" + localPipeInteger.getValue() + "]条");
          localQueryResult.setResults(localVector2);
          if (localIcaConnection != null)
            localIcaConnection.close();
          this.log.debug(localQueryResult.getMessage());
          return localQueryResult;
        }
        localVector2.add(getCertInfo((Properties)localVector1.elementAt(j)));
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localQueryResult.setReturnCode(1L);
        if (localIcaConnection != null)
          localIcaConnection.close();
      }
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }

  public Map raQueryPassCode(String paramString1, String paramString2, String paramString3)
    throws IcaUnavailable
  {
    QueryResult localQueryResult = new QueryResult();
    Properties localProperties1 = new Properties();
    Properties localProperties2 = new Properties();
    localProperties1.setProperty("OPERATION", "Query");
    localProperties1.setProperty("USER_NAME", paramString1);
    localProperties1.setProperty("USER_EMAIL", paramString2);
    localProperties1.setProperty("SQL_TEMPLATE_FILENAME", paramString3);
    localProperties1.setProperty("SQL_RECORDS_INDEX", "0");
    localProperties1.setProperty("SQL_RECORDS_ALL", "YES");
    IcaConnection localIcaConnection = null;
    HashMap localHashMap = new HashMap();
    localHashMap.put("result", "true");
    try
    {
      localIcaConnection = getConnection();
      long l = localIcaConnection.request(localProperties1, localProperties2);
      localQueryResult.setReturnCode(l);
      if (l == 0L)
      {
        setSqlResultCharacter(localProperties2, localQueryResult);
        localHashMap.put("PASSCODE", localProperties2.getProperty("PASSCODE"));
        localHashMap.put("PASSCODE_STATUS", localProperties2.getProperty("PASSCODE_STATUS"));
        localHashMap.put("PASSCODE_ID", localProperties2.getProperty("PASSCODE_ID"));
      }
      while (true)
      {
        if (localIcaConnection != null)
          localIcaConnection.close();
        this.log.debug(localQueryResult.getMessage());
        return localHashMap;
        localHashMap.put("result", "false");
      }
    }
    catch (IOException localIOException)
    {
      localHashMap.put("result", "false");
      return localHashMap;
    }
    finally
    {
      if (localIcaConnection != null)
        localIcaConnection.close();
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.ica.ra.RaAdminManager
 * JD-Core Version:    0.6.2
 */